package cn.tedu.contorller;

import cn.tedu.dao.ProductDao;
import cn.tedu.entity.Product;
import cn.tedu.entity.User;
import org.thymeleaf.context.Context;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/LikeServlet")
public class LikeServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        Context context = new Context();

        ProductDao dao = new ProductDao();
        HttpSession session = request.getSession();
        String likeId = (String) session.getAttribute("like"+id);
        if (likeId==null){
            dao.addlikeCount(id);
            session.setAttribute("like"+id,id);
        }
        response.sendRedirect(request.getContextPath()+"/DetailServlet?id="+id);
    }
}
